//
//  MazeObjectView.m
//  BoxMan
//
//  Created by wang yiping on 11-2-15.
//  Copyright 2011 app. All rights reserved.
//

#import "MazeObjectView.h"


@implementation MazeObjectView
@synthesize delegate;
@synthesize objectType;
@synthesize objectPosition;

- (id)initWithImage:(UIImage *)image {
	self = [super initWithImage:image];
	if (self) {
		[self setUserInteractionEnabled:YES];
		[self setExclusiveTouch:YES];
	}
	return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // store the location of the starting touch so we can decide when we've moved far enough to drag
	isOutOfBlock = NO;
    touchLocation = [[touches anyObject] locationInView:self];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint newTouchLocation = [[touches anyObject] locationInView:self];
    if ((newTouchLocation.x > ([self frame].origin.x + [self frame].size.width)) || (newTouchLocation.y > ([self frame].origin.y + [self frame].size.height)) || (newTouchLocation.x < [self frame].origin.x) || (newTouchLocation.y < [self frame].origin.y)) {
        isOutOfBlock = YES;
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	if (!isOutOfBlock) {
		if ([delegate respondsToSelector:@selector(mazeObjectWasTapped:)])
			[delegate mazeObjectWasTapped:self];
	} 
}
@end
